package com.mall.server.controller.sms;


import com.mall.model.domain.SmsHomeNewProduct;
import com.mall.model.vo.CommonPage;
import com.mall.model.vo.CommonResult;
import com.mall.server.service.sms.SmsHomeNewProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@CrossOrigin
@RestController
@RequestMapping("/home/newProduct")
public class SmsHomeNewProductController {

    @Autowired
    private SmsHomeNewProductService smsHomeNewProductService;

    /**
     * 分页查询首页新品
     */
    @GetMapping("/list")
    public CommonResult list(@RequestParam(defaultValue = "1") Integer pageNum
            , @RequestParam(defaultValue = "10") Integer pageSize
            , SmsHomeNewProduct newProduct) {

        CommonPage cp = smsHomeNewProductService.list(pageNum, pageSize, newProduct);

        return CommonResult.success(cp);
    }

    /**
     * 添加首页新品
     */
    @PostMapping("/create")
    public CommonResult create(@RequestBody List<SmsHomeNewProduct> homeNewProductList) {

        smsHomeNewProductService.create(homeNewProductList);

        return CommonResult.success(null);
    }

    /**
     * 批量删除首页新品
     */
    @PostMapping("/delete")
    public CommonResult delete(@RequestParam("ids") List<Long> ids) {

        smsHomeNewProductService.delete(ids);

        return CommonResult.success(null);
    }

    /**
     * 批量修改首页新品状态
     */
    @PostMapping("/update/recommendStatus")
    public CommonResult update(@RequestParam("ids") List<Long> ids,
                               SmsHomeNewProduct homeNewProduct) {

        smsHomeNewProductService.update(ids, homeNewProduct);

        return CommonResult.success(null);
    }

    /**
     * 修改首页新品排序
     */
    @PostMapping("/update/sort/{id}")
    public CommonResult updateSort(@PathVariable Integer id,
                                   SmsHomeNewProduct homeNewProduct) {

        smsHomeNewProductService.updateSort(id, homeNewProduct);

        return CommonResult.success(null);
    }


}
